home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
libgutil
/
acc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
157 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* acc -
* Software accumulation buffer implementation follows
*
*
* Paul Haeberli - 1989
*
* exports
*
void newacc(nx,ny)
void clearacc()
void addltoacc(l)
void addtoacc()
void avgacc(l)
void saveacc(name)
ACCPNTS *openpnts(name)
int numpnts(ap)
void getaccpnt(ap,n,xo,yo)
*
*/
#include "gl.h"
#include "stdio.h"
#include "acc.h"
static int nacc, xsize, ysize;
static short *accr;
static short *accg;
static short *accb;
static unsigned long *lbuf;
void clearacc()
{
int n;
nacc = 0;
n = xsize*ysize;
bzero(accr,n*sizeof(short));
bzero(accg,n*sizeof(short));
bzero(accb,n*sizeof(short));
}
void newacc(nx,ny)
int nx, ny;
{
xsize = nx;
ysize = ny;
accr = (short *)mymalloc(xsize*ysize*sizeof(short));
accg = (short *)mymalloc(xsize*ysize*sizeof(short));
accb = (short *)mymalloc(xsize*ysize*sizeof(short));
lbuf = (unsigned long *)mymalloc(xsize*ysize*sizeof(long));
clearacc();
}
void addltoacc(l)
unsigned long *l;
{
short *r, *g, *b;
int n;
nacc++;
n = xsize*ysize;
r = accr;
g = accg;
b = accb;
while(n--) {
*r++ += ((*l)>>0) & 0xff;
*g++ += ((*l)>>8) & 0xff;
*b++ += ((*l)>>16) & 0xff;
l++;
}
}
void addtoacc()
{
lrectread(0,0,xsize-1,ysize-1,lbuf);
addltoacc(lbuf);
}
void avgacc(l)
unsigned long *l;
{
int n;
short *r, *g, *b;
int ar, ag, ab;
r = accr;
g = accg;
b = accb;
n = xsize*ysize;
while(n--) {
ar = *r++/nacc;
ag = *g++/nacc;
ab = *b++/nacc;
*l++ = (ar<<0)+(ag<<8)+(ab<<16);
}
}
void saveacc(name)
char *name;
{
avgacc(lbuf);
longstoimage(lbuf,xsize,ysize,3,name);
}
ACCPNTS *openpnts(name)
char *name;
{
int i;
FILE *inf;
ACCPNTS *ap;
inf = fopen(name,"r");
if(!inf) {
fprintf(stderr,"openpnts: can't open input file %s\n",name);
exit(1);
}
ap = (ACCPNTS *)mymalloc(sizeof(ACCPNTS));
fscanf(inf,"%d\n",&ap->npoints);
ap->pdata = (float *)mymalloc(2*ap->npoints*sizeof(float));
for(i=0; i<ap->npoints; i++)
fscanf(inf,"%f %f\n",ap->pdata+(2*i),ap->pdata+(2*i+1));
fclose(inf);
return ap;
}
int numpnts(ap)
ACCPNTS *ap;
{
return ap->npoints;
}
void getaccpnt(ap,n,xo,yo)
ACCPNTS *ap;
int n;
float *xo, *yo;
{
n = n%ap->npoints;
*xo = ap->pdata[2*n];
*yo = ap->pdata[2*n+1];
}